package com.gollum.web.controller.monitor;

import com.alibaba.fastjson2.JSONObject;
import com.gollum.common.domain.response.RestResponse;
import com.gollum.common.utils.MessageUtils;
import com.gollum.common.web.controller.BaseController;
import com.gollum.system.domain.request.SysOperLogRequest;
import com.gollum.system.service.SysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 操作日志controller
 *
 * @author Herther
 * @createTime 2022年09月15日 23:34:00
 * @since 1.0.0
 */
@Api(tags = "系统监控中心-操作日志")
@RestController
@RequestMapping("/operlog")
public class SysOperLogController extends BaseController {


    @Autowired
    protected SysOperLogService sysOperLogService;

    @PostMapping("/list")
    @ApiOperation(value = "分页查询操作日志")
    public RestResponse listPage(@RequestBody JSONObject jsonObject) {
        buildPageQuery(jsonObject);
        return RestResponse.success(sysOperLogService.listPage(this.toJavaObjectParams(SysOperLogRequest.class, jsonObject)));
    }


    @GetMapping("/get/{id}")
    @ApiOperation(value= "根据ID查询操作日志详情")
    public RestResponse getDetail(@PathVariable("id") Long id) {
        return RestResponse.success(sysOperLogService.getDetailById(id));
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除操作日志详情")
    public RestResponse remove(@PathVariable("id") Long[] ids) {
        sysOperLogService.removeByIds(Arrays.asList(ids));
        return RestResponse.success().setMsg(MessageUtils.getMsg("resp.delete_success"));
    }

}
